var bproduct = function(){
	this.box = $("#formpage");	//表单
	this.input = this.box.find("span.at_text>input");
	this.productName = $("#productName");//商品名称
	this.productNameCheck = false;
	this.companyName = $("#companyName");//生产厂家
	this.companyNameCheck = false;
	
	this.btn = $("#reg_sub");	//提交按钮

	var me = this;  //page  1快速 2邮箱 3手机 4修改密码 5创建安全密码 6修改安全密码 7重设密码 
	
	var isloading=false;
	
	//提示信息
	var h_on = '<em class="on">';	
	var h_err = '<em class="orr"><u class="at_msg m_3_e"></u>';
	var recvUserId_o = h_on+'<span id="namecount">·请选择收货方</span></em>';
	
	//错误
	var productName_e1 = h_err+'商品名称不能为空</em>';
	var companyName_e1 = h_err+'生产厂家不能为空</em>';
	
	//正确
	var name_g = '<em><u class="at_msg m_3_o"></u></em>';
	var name_ld = '<em class="ld"><u class="at_msg at_write"></u>正在检测中……</em>';

	function txt(t){var a=t.parents(".at_text");return a};	
	this.input.focus(function(){//获得焦点
		txt($(this)).attr("class","at_text t_1_i");		
		txt($(this)).find("em").remove();	
		$(this).parents("dd").css("z-index",999);
	})
	this.input.blur(function(){//失去焦点
		txt($(this)).attr("class","at_text t_1_d");
		txt($(this)).find("em").remove();
		$(this).parents("dd");
	})
	var inErr = function(a,b){//错误
		var at_text = txt(a);
		at_text.attr("class","at_text t_1_e");
		at_text.find("em").remove();
		at_text.append(b);
		return false;
	}
	var inOk = function(a){//正确
		var at_text = txt(a);
		at_text.attr("class","at_text t_1_o");
		at_text.find("em").remove();
		at_text.append(name_g);
	}
	var inPass = function(a){//正常，不加“正确”图标
		var at_text = txt(a);
		at_text.attr("class","at_text t_1_o");
		at_text.find("em").remove();
		//at_text.append(name_g);
	}
	
	var namelength = function(a) {//统计字符长度，中文算二个字符
		var name = a.val(),
			length = 0;
		for(var i=0; i<name.length; i++) {
			if(/[\u4e00-\u9fa5]/.test(name.charAt(i))) length+=2;
			else length+=1;
		}
		return length;
	};
	
	var strTrimLength = function(a) {//统计字符长度，不包括空格在内
		var name = a.val(),
			length = 0;
		name=$.trim(name);
		for(var i=0; i<name.length; i++) {
			if(/[\u4e00-\u9fa5]/.test(name.charAt(i))) length+=2;
			else length+=1;
		}
		return length;
	};
	
	var clearEmpty = function(O) {//禁止输入空格
		O.val(O.val().replace(/\s*/g,""));
	}
	
	this.productNameCheckFun = function(i,s){//商品
		var len = strTrimLength(i);
        if (len == 0) {//8-50字符 (1汉字等于2字符)
            me.productNameCheck = inErr(i,productName_e1);			
			return;
        }
		inPass(i);				
		me.productNameCheck = true;
	}
	
	this.companyNameCheckFun = function(i,s){//厂家	
		var len = strTrimLength(i);
        if (len == 0) {//8-50字符 (1汉字等于2字符)
            me.companyNameCheck = inErr(i,companyName_e1);			
			return;
        }
		inPass(i);				
		me.companyNameCheck = true;
	}
	
	
	this.btn.click(function(){//按钮提交
	    if(isloading){return false;}
		if(me.productNameCheck==false){
			inPass(me.productName);
			me.productNameCheckFun(me.productName,false);
		}
		
		if(me.companyNameCheck==false){
			inPass(me.companyName);
			me.companyNameCheckFun(me.companyName,false);
		}
		
		if(!me.productNameCheck || !me.companyNameCheck) return false;
		return me.box.submit();
	});
	
	
	//重置表单
	var clearForm = function(){
	
	};
	
	this.productName.focus(function(){
		me.productName.isCheck=false;
	})
	this.productName.blur(function(){me.productNameCheckFun(me.productName)});
	
	this.companyName.focus(function(){
		me.companyName.isCheck=false;
	})
	this.companyName.blur(function(){me.companyNameCheckFun(me.companyName)});
	
	//me.box.submit(function(){ 难道这里不去掉会一直提交？
	//    me.btn.click();
	//    return false;
	//});
}
